﻿using Quartz;
using System.Text.Json;
using WeskyQuantDemo.Models;

namespace WeskyQuantDemo.Services.Jobs
{
    [DisallowConcurrentExecution]
    public class GetHistoryPriceJob : IJob
    {
        private IQuantDataService _quantDataService;
        public GetHistoryPriceJob(IQuantDataService quantDataService)
        {
            _quantDataService = quantDataService;
        }
        public GetHistoryPriceJob()
        {

        }

        public async Task Execute(IJobExecutionContext context)
        {
            var apiUrl = "http://127.0.0.1:8080/api/public/stock_zh_a_hist";
            string startDate = DateTime.Now.AddDays(-30).ToString("yyyyMMdd");
            string endDate = DateTime.Now.ToString("yyyyMMdd");

            var paramData = new Dictionary<string, string>
            {
                { "symbol", "300532" },
                { "period", "daily" },
                { "start_date", startDate },
                { "end_date", endDate },
                { "adjust", "qfq" }
            };

            _quantDataService = Global.GlobalServiceProvider.GetService<IQuantDataService>();
            var result = await _quantDataService.GetWithQueryParamsAsync(apiUrl, paramData);
            IEnumerable<StockHistoryInfo> stockHistoryInfos = JsonSerializer.Deserialize<IEnumerable<StockHistoryInfo>>(result);

            // TODO:根据获取到的价格数据，或者结合其他数据进行一些计算。

        }
    }
}
